//
//  RegisterCtr.m
//  Traveling
//
//  Created by 曹秀云 on 15/6/4.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "RegisterCtr.h"
#import "MineDataTool.h"
@interface RegisterCtr ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *accountTextFiled;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextFiled;
@property (weak, nonatomic) IBOutlet UIButton *checkBtn;
@property (weak, nonatomic) IBOutlet UIButton *okBtn;
@end

@implementation RegisterCtr

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"黄坡智慧旅游"];
    [self.accountTextFiled setDelegate:self];
    [self.pwdTextFiled setDelegate:self];
    [self.okBtn addTarget:self action:@selector(RegisterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)RegisterBtnClick:(UIButton *)btn{
    if (ISBLANK(self.accountTextFiled.text)) {
        [DialogUtils showTipsWithView:nil String:@"注册手机号不能为空！"];
        return;
    }
    
    
    if (!self.accountTextFiled.text.isValidatePhone)
    {
        [DialogUtils showTipsWithView:nil String:@"用户名不合法！"];
        return;
    }
    
    if (ISBLANK(self.pwdTextFiled.text)){
        [DialogUtils showTipsWithView:nil String:@"密码不能为空"];
        return;
    }
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"user_name"] = self.accountTextFiled.text;
    params[@"password"] = self.pwdTextFiled.text;
   
    [MineDataTool registerWithParams:params success:^(RegisterResult *result) {
        if (result.isSucc) {
            [DialogUtils showTipsWithView:nil String:@"注册成功"];
            if (!result.id) {
                [result saveUserResult];
            }
            [self.navigationController popToRootViewControllerAnimated:YES];
        }else{
            
            [DialogUtils showTipsWithView:nil String:result.msg];
        }
        
    } failure:^(NSError *error) {
        [DialogUtils showTipsWithView:nil String:@"注册失败"];
    }];

}

@end
